# -*- coding:utf-8 -*-
import sys
from PySide2.QtGui import *
from PySide2.QtCore import *
from PySide2.QtWidgets import *
from utils.Detection import *
try:
    import maya.cmds as cmds
    import maya.mel as mel
    import maya.app.renderSetup.model.renderSetup as renderSetup
    import pymel.core as pm
except Exception as test_ERR:
    print('test')

class OptimizeSceneDetection(QWidget):

    def __init__(self,result_info,font,btn_style=None):
        super(OptimizeSceneDetection, self).__init__()
        self.error_style = 'QLabel{color: #f00f00}'
        self.ok_style = 'QLabel{color: #87fa14}'
        self.main_layout = QHBoxLayout()
        self.detect_label = QLabel(u'删除无用节点与层:')
        self.detect_label.setFont(font)
        self.detect_result = QLabel(result_info['result'])
        style = self.error_style if result_info['result'] == 'ERROR' else self.ok_style
        self.detect_result.setStyleSheet(style)
        self.detect_info = QLabel(result_info['info'])
        self.main_layout.addWidget(self.detect_label)
        self.main_layout.addWidget(self.detect_result)
        self.main_layout.addWidget(self.detect_info)
        self.setLayout(self.main_layout)

class MainCameraDetection(QWidget):

    def __init__(self,result_info,font,btn_style=None):
        super(MainCameraDetection, self).__init__()
        self.error_style = 'QLabel{color: #f00f00}'
        self.ok_style = 'QLabel{color: #87fa14}'
        self.main_layout = QHBoxLayout()
        self.detect_label = QLabel(u'主相机检测:')
        self.detect_label.setFont(font)
        self.detect_result = QLabel(result_info['result'])
        style = self.error_style if result_info['result'] == 'ERROR' else self.ok_style
        self.detect_result.setStyleSheet(style)
        self.detect_info = QLabel(result_info['info'])
        self.main_layout.addWidget(self.detect_label)
        self.main_layout.addWidget(self.detect_result)
        self.main_layout.addWidget(self.detect_info)
        self.setLayout(self.main_layout)

class CameraDetection(QWidget):

    def __init__(self,result_info,font,btn_style=None):
        super(CameraDetection, self).__init__()
        self.error_style = 'QLabel{color: #f00f00}'
        self.ok_style = 'QLabel{color: #87fa14}'
        self.main_layout = QHBoxLayout()
        self.detect_label = QLabel(u'是否有相机:')
        self.detect_label.setFont(font)
        self.detect_result = QLabel(result_info['result'])
        style = self.error_style if result_info['result'] == 'ERROR' else self.ok_style
        self.detect_result.setStyleSheet(style)
        self.detect_info = QLabel(result_info['info'])
        self.main_layout.addWidget(self.detect_label)
        self.main_layout.addWidget(self.detect_result)
        self.main_layout.addWidget(self.detect_info)
        self.setLayout(self.main_layout)

class CameraBGImgDetection(QWidget):

    def __init__(self,result_info,font,btn_style=None):
        super(CameraBGImgDetection, self).__init__()
        self.error_style = 'QLabel{color: #f00f00}'
        self.ok_style = 'QLabel{color: #87fa14}'
        self.main_layout = QHBoxLayout()
        self.detect_label = QLabel(u'相机背景图:')
        self.detect_label.setFont(font)
        self.detect_result = QLabel(result_info['result'])
        style = self.error_style if result_info['result'] == 'ERROR' else self.ok_style
        self.detect_result.setStyleSheet(style)
        self.detect_info = QLabel(result_info['info'])
        self.main_layout.addWidget(self.detect_label)
        self.main_layout.addWidget(self.detect_result)
        self.main_layout.addWidget(self.detect_info)
        self.setLayout(self.main_layout)

class LockCameraDetection(QWidget):
    """
    跟踪检测相机参数是否固定
    """
    def __init__(self,result_info,font,btn_style=None):
        super(LockCameraDetection, self).__init__()
        self.error_style = 'QLabel{color: #f00f00}'
        self.ok_style = 'QLabel{color: #87fa14}'
        self.main_layout = QVBoxLayout()
        self.detect_layout = QHBoxLayout()
        self.detect_label = QLabel(u'相机参数固定:')
        self.detect_label.setFont(font)
        self.detect_result = QLabel(result_info['result'])
        style = self.error_style if result_info['result'] == 'ERROR' else self.ok_style
        self.detect_result.setStyleSheet(style)
        self.lock_camera_btn = QPushButton(u'锁定相机')
        self.lock_camera_btn.setStyleSheet(btn_style)
        self.lock_camera_btn.clicked.connect(self._lock_camera)
        self.lock_camera_btn.setHidden(True if not result_info['info'] else False)
        self.detect_layout.addWidget(self.detect_label)
        self.detect_layout.addWidget(self.detect_result)
        self.detect_layout.addWidget(self.lock_camera_btn)
        self.detect_info = QListWidget()
        self.detect_info.setFixedHeight(100)
        self.detect_info.addItems(result_info['info'])
        self.detect_info.setHidden(True if not result_info['info'] else False)
        self.main_layout.addLayout(self.detect_layout)
        self.main_layout.addWidget(self.detect_info)
        self.setLayout(self.main_layout)


    def _lock_camera(self):
        try:
            result = lockCamera()
            if result:
                self.detect_result.setText('OK')
                self.detect_result.setStyleSheet(self.ok_style)
        except Exception as _lock_camera_ERR:
            pass


class NameDetection(QWidget):

    def __init__(self,result_info,font,btn_style=None):
        super(NameDetection, self).__init__()
        self.error_style = 'QLabel{color: #f00f00}'
        self.ok_style = 'QLabel{color: #87fa14}'
        self.main_layout = QVBoxLayout()
        self.detect_layout = QHBoxLayout()
        self.detect_label = QLabel(u'重名检测:')
        self.detect_label.setFont(font)
        self.detect_result = QLabel(result_info['result'])
        style = self.error_style if result_info['result'] == 'ERROR' else self.ok_style
        self.detect_result.setStyleSheet(style)
        self.auto_rename_btn = QPushButton(u'自动重命名')
        self.auto_rename_btn.setStyleSheet(btn_style)
        self.auto_rename_btn.clicked.connect(self._auto_rename)
        self.auto_rename_btn.setHidden(True if not result_info['info'] else False)
        self.detect_layout.addWidget(self.detect_label)
        self.detect_layout.addWidget(self.detect_result)
        self.detect_layout.addWidget(self.auto_rename_btn)
        self.detect_info = QListWidget()
        self.detect_info.itemClicked.connect(self._choose_item)
        self.detect_info.setFixedHeight(100)
        self.detect_info.addItems(result_info['info'])
        self.detect_info.setHidden(True if not result_info['info'] else False)
        self.main_layout.addLayout(self.detect_layout)
        self.main_layout.addWidget(self.detect_info)
        self.setLayout(self.main_layout)

    def _choose_item(self,item):
        obj = item.text()
        try:
            cmds.select(obj)
        except :
            pass

    def _auto_rename(self):
        try:
            result = auto_rename()
            if result:
                self.detect_info.clear()
                self.detect_result.setText('OK')
                self.detect_result.setStyleSheet(self.ok_style)
        except Exception as _auto_rename_ERR:
            pass

class DisplayLayoutDetection(QWidget):
    """
    跟踪不检查显示层
    """
    def __init__(self,result_info,font,btn_style=None):
        super(DisplayLayoutDetection, self).__init__()
        self.error_style = 'QLabel{color: #f00f00}'
        self.ok_style = 'QLabel{color: #87fa14}'
        self.main_layout = QVBoxLayout()
        self.detect_layout = QHBoxLayout()
        self.detect_label = QLabel(u'显示层检测:')
        self.detect_label.setFont(font)
        self.detect_result = QLabel(result_info['result'])
        style = self.error_style if result_info['result'] == 'ERROR' else self.ok_style
        self.detect_result.setStyleSheet(style)
        self.remove_displayLayout_btn = QPushButton(u'清空显示层')
        self.remove_displayLayout_btn.setStyleSheet(btn_style)
        self.remove_displayLayout_btn.clicked.connect(self._remove_displayLayout)
        self.remove_displayLayout_btn.setHidden(True if not result_info['info'] else False)
        self.detect_layout.addWidget(self.detect_label)
        self.detect_layout.addWidget(self.detect_result)
        self.detect_layout.addWidget(self.remove_displayLayout_btn)

        self.detect_info = QListWidget()
        self.detect_info.setFixedHeight(100)
        self.detect_info.addItems(result_info['info'])
        self.detect_info.setHidden(True if not result_info['info'] else False)

        self.main_layout.addLayout(self.detect_layout)
        self.main_layout.addWidget(self.detect_info)
        self.setLayout(self.main_layout)


    def _remove_displayLayout(self):
        try:
            clearDisplayLayers()
            self.detect_info.clear()
            self.detect_result.setText('OK')
            self.detect_result.setStyleSheet(self.ok_style)
        except Exception as _remove_displayLayout_ERR:
            pass

class RenderLayoutDetection(QWidget):
    """
    跟踪不检查显示层
    """
    def __init__(self,result_info,font,btn_style=None):
        super(RenderLayoutDetection, self).__init__()
        self.error_style = 'QLabel{color: #f00f00}'
        self.ok_style = 'QLabel{color: #87fa14}'
        self.main_layout = QVBoxLayout()
        self.detect_layout = QHBoxLayout()
        self.detect_label = QLabel(u'渲染层检测:')
        self.detect_label.setFont(font)
        self.detect_result = QLabel(result_info['result'])
        style = self.error_style if result_info['result'] == 'ERROR' else self.ok_style
        self.detect_result.setStyleSheet(style)

        self.remove_renderLayout_btn = QPushButton(u'清空渲染层')
        self.remove_renderLayout_btn.setStyleSheet(btn_style)
        self.remove_renderLayout_btn.clicked.connect(self._remove_renderLayout)
        self.remove_renderLayout_btn.setHidden(True if not result_info['info'] else False)
        self.detect_layout.addWidget(self.detect_label)
        self.detect_layout.addWidget(self.detect_result)
        self.detect_layout.addWidget(self.remove_renderLayout_btn)

        self.detect_info = QListWidget(self)
        self.detect_info.setFixedHeight(100)
        self.detect_info.addItems(result_info['info'])
        self.detect_info.setHidden(True if not result_info['info'] else False)

        self.main_layout.addLayout(self.detect_layout)
        self.main_layout.addWidget(self.detect_info)

        self.setLayout(self.main_layout)

    def _remove_renderLayout(self):
        try:
            clearRenderLayers()
            self.detect_info.clear()
            self.detect_result.setText('OK')
            self.detect_result.setStyleSheet(self.ok_style)
        except Exception as _remove_displayLayout_ERR:
            pass


class PrimMaterialDetetion(QWidget):
    """
    材质检测,是否有按面上材质
    """
    def __init__(self,result_info,font,btn_style=None):
        super(PrimMaterialDetetion, self).__init__()
        self.error_style = 'QLabel{color: #f00f00}'
        self.ok_style = 'QLabel{color: #87fa14}'
        self.main_layout = QVBoxLayout()
        self.detect_layout = QHBoxLayout()
        self.detect_label = QLabel(u'面上材质:')
        self.detect_label.setFont(font)
        self.detect_result = QLabel(result_info['result'])
        style = self.error_style if result_info['result'] == 'ERROR' else self.ok_style
        self.detect_result.setStyleSheet(style)
        self.detect_layout.addWidget(self.detect_label)
        self.detect_layout.addWidget(self.detect_result)
        self.detect_info = QListWidget()
        self.detect_info.itemClicked.connect(self._choose_item)
        self.detect_info.setFixedHeight(100)
        self.detect_info.addItems(result_info['info'])
        self.detect_info.setHidden(True if not result_info['info'] else False)
        self.main_layout.addLayout(self.detect_layout)
        self.main_layout.addWidget(self.detect_info)
        self.setLayout(self.main_layout)

    def _choose_item(self, item):
        obj = item.text()
        try:
            cmds.select(obj)
        except:
            pass


class FileMaterialDetetion(QWidget):
    """
    是否材质贴图是否在网盘上
    """
    def __init__(self,result_info,font,btn_style=None):
        super(FileMaterialDetetion, self).__init__()
        self.error_style = 'QLabel{color: #f00f00}'
        self.ok_style = 'QLabel{color: #87fa14}'
        self.main_layout = QVBoxLayout()
        self.detect_layout = QHBoxLayout()
        self.detect_label = QLabel(u'贴图路径:')
        self.detect_label.setFont(font)
        self.detect_result = QLabel(result_info['result'])
        style = self.error_style if result_info['result'] == 'ERROR' else self.ok_style
        self.detect_result.setStyleSheet(style)
        self.detect_layout.addWidget(self.detect_label)
        self.detect_layout.addWidget(self.detect_result)
        self.detect_info = QListWidget()
        self.detect_info.itemClicked.connect(self._choose_item)
        self.detect_info.setFixedHeight(100)
        self.detect_info.addItems(result_info['info'])
        self.detect_info.setHidden(True if not result_info['info'] else False)
        self.main_layout.addLayout(self.detect_layout)
        self.main_layout.addWidget(self.detect_info)
        self.setLayout(self.main_layout)

    def _choose_item(self, item):
        obj = item.text()
        try:
            cmds.select(obj)
        except:
            pass

class UVDetetion(QWidget):
    """
    UVset检测
    """
    def __init__(self,result_info,font,btn_style=None):
        super(UVDetetion, self).__init__()
        self.error_style = 'QLabel{color: #f00f00}'
        self.ok_style = 'QLabel{color: #87fa14}'
        self.main_layout = QVBoxLayout()
        self.detect_layout = QHBoxLayout()
        self.detect_label = QLabel(u'UVset:')
        self.detect_label.setFont(font)
        self.detect_result = QLabel(result_info['result'])
        style = self.error_style if result_info['result'] == 'ERROR' else self.ok_style
        self.detect_result.setStyleSheet(style)
        self.detect_layout.addWidget(self.detect_label)
        self.detect_layout.addWidget(self.detect_result)
        self.detect_info = QListWidget()
        self.detect_info.itemClicked.connect(self._choose_item)
        self.detect_info.setFixedHeight(100)
        self.detect_info.addItems(result_info['info'])
        self.detect_info.setHidden(True if not result_info['info'] else False)
        self.main_layout.addLayout(self.detect_layout)
        self.main_layout.addWidget(self.detect_info)
        self.setLayout(self.main_layout)

    def _choose_item(self, item):
        obj = item.text()
        try:
            cmds.select(obj)
        except:
            pass


# class ColorSpaceDetetion(QWidget):
#     """
#     UVset检测
#     """
#     def __init__(self,result_info,font,btn_style=None):
#         super(ColorSpaceDetetion, self).__init__()
#         self.error_style = 'QLabel{color: #f00f00}'
#         self.ok_style = 'QLabel{color: #87fa14}'
#         self.main_layout = QVBoxLayout()
#         self.detect_layout = QHBoxLayout()
#         self.detect_label = QLabel(u'色彩空间:')
#         self.detect_label.setFont(font)
#         self.detect_result = QLabel(result_info['result'])
#         style = self.error_style if result_info['result'] == 'ERROR' else self.ok_style
#         self.detect_result.setStyleSheet(style)
#         self.detect_layout.addWidget(self.detect_label)
#         self.detect_layout.addWidget(self.detect_result)
#         self.detect_info = QListWidget()
#         self.detect_info.itemClicked.connect(self._choose_item)
#         self.detect_info.setFixedHeight(100)
#         self.detect_info.addItems(result_info['info'])
#         self.detect_info.setHidden(True if not result_info['info'] else False)
#         self.main_layout.addLayout(self.detect_layout)
#         self.main_layout.addWidget(self.detect_info)
#         self.setLayout(self.main_layout)
#
#     def _choose_item(self, item):
#         obj = item.text()
#         try:
#             cmds.select(obj)
#         except:
#             pass

class ColorSpaceDetetion(QWidget):
    """
    色彩空间检测检测
    """
    def __init__(self,result_info,font=None,btn_style=None):
        super(ColorSpaceDetetion, self).__init__()
        self.info = result_info['info']
        self.error_style = 'QLabel{color: #f00f00}'
        self.ok_style = 'QLabel{color: #87fa14}'
        self.main_layout = QVBoxLayout()
        self.detect_layout = QHBoxLayout()
        self.detect_label = QLabel(u'色彩空间:')
        self.detect_label.setFont(font)
        self.detect_result = QLabel(result_info['result'])
        self.detect_result = QLabel('wwwww')
        style = self.error_style if result_info['result'] == 'ERROR' else self.ok_style
        self.detect_result.setStyleSheet(style)
        self.detect_layout.addWidget(self.detect_label)
        self.detect_layout.addWidget(self.detect_result)
        self.detect_info_layout = QHBoxLayout()
        self.color_space_layout = QVBoxLayout()
        self.color_space_label = QLabel('ColorSpace')
        self.color_space_list = QListWidget()
        self.color_space_list.setMaximumWidth(100)
        self.color_space_list.itemClicked.connect(self._choose_color_space)
        self.color_space_layout.addWidget(self.color_space_label)
        self.color_space_layout.addWidget(self.color_space_list)
        self.file_layout = QVBoxLayout()
        self.file_label = QLabel(u'file节点')
        self.file_list = QListWidget()
        self.file_list.setMaximumWidth(100)
        self.file_list.itemClicked.connect(self._choose_item)
        self.file_layout.addWidget(self.file_label)
        self.file_layout.addWidget(self.file_list)
        self.color_space_list.addItems(list(self.info.keys()))
        self.color_space_list.setHidden(True if not result_info['info'] else False)
        self.file_list.setHidden(True if not result_info['info'] else False)
        self.detect_info_layout.addLayout(self.color_space_layout)
        self.detect_info_layout.addLayout(self.file_layout)
        self.main_layout.addLayout(self.detect_layout)
        self.main_layout.addLayout(self.detect_info_layout)
        self.setLayout(self.main_layout)



    def _choose_color_space(self,item):
        self.file_list.clear()
        color_space = item.text()
        files = self.info.get(color_space,[])
        self.file_list.addItems(files)

    def _choose_item(self, item):
        obj = item.text()
        try:
            cmds.select(obj)
        except:
            pass

class DSODetetion(QWidget):
    """
    是否材质贴图是否在网盘上
    """
    def __init__(self,result_info,font,btn_style=None):
        super(DSODetetion, self).__init__()
        self.error_style = 'QLabel{color: #f00f00}'
        self.ok_style = 'QLabel{color: #87fa14}'
        self.main_layout = QVBoxLayout()
        self.detect_layout = QHBoxLayout()
        self.detect_label = QLabel(u'DSO路径:')
        self.detect_label.setFont(font)
        self.detect_result = QLabel(result_info['result'])
        style = self.error_style if result_info['result'] == 'ERROR' else self.ok_style
        self.detect_result.setStyleSheet(style)
        self.detect_layout.addWidget(self.detect_label)
        self.detect_layout.addWidget(self.detect_result)
        self.detect_info = QListWidget()
        self.detect_info.itemClicked.connect(self._choose_item)
        self.detect_info.setFixedHeight(100)
        self.detect_info.addItems(result_info['info'])
        self.detect_info.setHidden(True if not result_info['info'] else False)
        self.main_layout.addLayout(self.detect_layout)
        self.main_layout.addWidget(self.detect_info)
        self.setLayout(self.main_layout)

    def _choose_item(self, item):
        obj = item.text()
        try:
            cmds.select(obj)
        except:
            pass


class OverFourFaceDetetion(QWidget):
    """
    超四边面检测
    """
    def __init__(self,result_info,font,btn_style=None):
        super(OverFourFaceDetetion, self).__init__()
        self.error_style = 'QLabel{color: #f00f00}'
        self.ok_style = 'QLabel{color: #87fa14}'
        self.main_layout = QVBoxLayout()
        self.detect_layout = QHBoxLayout()
        self.detect_label = QLabel(u'超四边面:')
        self.detect_label.setFont(font)
        self.detect_result = QLabel(result_info['result'])
        style = self.error_style if result_info['result'] == 'ERROR' else self.ok_style
        self.detect_result.setStyleSheet(style)
        self.detect_layout.addWidget(self.detect_label)
        self.detect_layout.addWidget(self.detect_result)
        self.detect_info = QListWidget()
        self.detect_info.itemClicked.connect(self._choose_item)
        self.detect_info.setFixedHeight(100)
        self.detect_info.addItems(result_info['info'])
        self.detect_info.setHidden(True if not result_info['info'] else False)
        self.main_layout.addLayout(self.detect_layout)
        self.main_layout.addWidget(self.detect_info)
        self.setLayout(self.main_layout)

    def _choose_item(self, item):
        obj = item.text()
        try:
            cmds.select(obj)
        except:
            pass


class RigGrpDetetion(QWidget):
    """
    骨骼组是否存在
    """
    def __init__(self,result_info,font,btn_style=None):
        super(RigGrpDetetion, self).__init__()
        self.error_style = 'QLabel{color: #f00f00}'
        self.ok_style = 'QLabel{color: #87fa14}'
        self.main_layout = QHBoxLayout()
        self.detect_label = QLabel(u'骨骼组:')
        self.detect_label.setFont(font)
        self.detect_result = QLabel(result_info['result'])
        style = self.error_style if result_info['result'] == 'ERROR' else self.ok_style
        self.detect_result.setStyleSheet(style)
        self.detect_info = QLabel(result_info['info'])
        self.main_layout.addWidget(self.detect_label)
        self.main_layout.addWidget(self.detect_result)
        self.main_layout.addWidget(self.detect_info)
        self.setLayout(self.main_layout)


class RigHumanDetetion(QWidget):
    """
    人物骨骼是否完整
    """
    def __init__(self,result_info,font,btn_style=None):
        super(RigHumanDetetion, self).__init__()
        self.error_style = 'QLabel{color: #f00f00}'
        self.ok_style = 'QLabel{color: #87fa14}'
        self.main_layout = QVBoxLayout()
        self.detect_layout = QHBoxLayout()
        self.detect_label = QLabel(u'人物骨骼:')
        self.detect_label.setFont(font)
        self.detect_result = QLabel(result_info['result'])
        style = self.error_style if result_info['result'] == 'ERROR' else self.ok_style
        self.detect_result.setStyleSheet(style)
        self.detect_layout.addWidget(self.detect_label)
        self.detect_layout.addWidget(self.detect_result)
        self.detect_info = QListWidget()
        self.detect_info.itemClicked.connect(self._choose_item)
        self.detect_info.setFixedHeight(100)
        self.detect_info.addItems(result_info['info'])
        self.detect_info.setHidden(True if not result_info['info'] else False)
        self.main_layout.addLayout(self.detect_layout)
        self.main_layout.addWidget(self.detect_info)
        self.setLayout(self.main_layout)

    def _choose_item(self, item):
        obj = item.text()
        try:
            cmds.select(obj)
        except:
            pass

class LightingDetetion(QWidget):
    """
    场景中是否有灯光，仅提醒
    """
    def __init__(self,result_info,font,btn_style=None):
        super(LightingDetetion, self).__init__()
        self.error_style = 'QLabel{color: #f00f00}'
        self.ok_style = 'QLabel{color: #87fa14}'
        self.tip_style = 'QLabel{color: #e4c258}'
        self.main_layout = QVBoxLayout()
        self.detect_layout = QHBoxLayout()
        self.detect_label = QLabel(u'场景灯光:')
        self.detect_label.setFont(font)
        self.detect_result = QLabel(result_info['result'])
        style = self.tip_style #if result_info['result'] == 'ERROR' else self.ok_style
        self.detect_result.setStyleSheet(style)
        self.detect_layout.addWidget(self.detect_label)
        self.detect_layout.addWidget(self.detect_result)
        self.detect_info = QListWidget()
        self.detect_info.itemClicked.connect(self._choose_item)
        self.detect_info.setFixedHeight(100)
        self.detect_info.addItems(result_info['info'])
        self.detect_info.setHidden(True if not result_info['info'] else False)
        self.main_layout.addLayout(self.detect_layout)
        self.main_layout.addWidget(self.detect_info)
        self.setLayout(self.main_layout)

    def _choose_item(self, item):
        obj = item.text()
        try:
            cmds.select(obj)
        except:
            pass

class YPosDetetion(QWidget):
    """
    模型是否有Y坐标小于0的点
    """
    def __init__(self,result_info,font,btn_style=None):
        super(YPosDetetion, self).__init__()
        self.error_style = 'QLabel{color: #f00f00}'
        self.ok_style = 'QLabel{color: #87fa14}'
        self.tip_style = 'QLabel{color: #e4c258}'
        self.main_layout = QVBoxLayout()
        self.detect_layout = QHBoxLayout()
        self.detect_label = QLabel(u'Y坐标低于0:')
        self.detect_label.setFont(font)
        self.detect_result = QLabel(result_info['result'])
        style = self.tip_style #if result_info['result'] == 'ERROR' else self.ok_style
        self.detect_result.setStyleSheet(style)
        self.detect_layout.addWidget(self.detect_label)
        self.detect_layout.addWidget(self.detect_result)
        self.detect_info = QListWidget()
        self.detect_info.itemClicked.connect(self._choose_item)
        self.detect_info.setFixedHeight(100)
        self.detect_info.addItems(result_info['info'])
        self.detect_info.setHidden(True if not result_info['info'] else False)
        self.main_layout.addLayout(self.detect_layout)
        self.main_layout.addWidget(self.detect_info)
        self.setLayout(self.main_layout)

    def _choose_item(self, item):
        obj = item.text()
        try:
            cmds.select(obj)
        except:
            pass


class DetetionWindow(QWidget):

    def __init__(self,pipeline,eps,task_name,checks,btn_style=None):
        super(DetetionWindow, self).__init__()


        self.big_font = QFont('',12,65)
        self.btn_style = """QPushButton{color:black}
                                  QPushButton:hover{color:red}
                                 QPushButton{background-color:#A9A9A9}
                                  QPushButton{border:2px}
                                  QPushButton{border-radius:3px}
                                  QPushButton{padding:1px 1px}"""

        self.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.Window)
        self.setWindowTitle(u'工程检测')
        self.main_layout = QVBoxLayout()
        self.main_label = QLabel(u'{}工程检测'.format(pipeline))
        self.main_label.setFont(self.big_font)
        self.main_label.setAlignment(Qt.AlignCenter)
        self.main_layout.addWidget(self.main_label)
        self.init_detection(pipeline,eps,checks,task_name)
        self.close_btn = QPushButton(u'关闭')
        self.close_btn.setFixedHeight(25)
        self.close_btn.setStyleSheet(self.btn_style)
        self.close_btn.clicked.connect(self._close)
        self.main_layout.addWidget(self.close_btn)
        self.setLayout(self.main_layout)



    def init_detection(self,pipeline,eps,checks,task_name=None):
        """

        :param pipeline:
        :param eps:
        :param checks:
        :param task_name:
        :return:
        """
        optimizeScene_result = checks.get('optimizeScene_result')
        optimizeSceneDetection = OptimizeSceneDetection(optimizeScene_result,self.big_font, self.btn_style)
        self.main_layout.addWidget(optimizeSceneDetection)
        if pipeline not in ['cfx']:
            checkName_result = checks.get('checkName_result')
            nameDetection = NameDetection(checkName_result,self.big_font, self.btn_style)
            self.main_layout.addWidget(nameDetection)

        checkLighting_result = checks.get('checkLighting_result')
        lightingDetetion = LightingDetetion(checkLighting_result,self.big_font, self.btn_style)
        self.main_layout.addWidget(lightingDetetion)

        if pipeline == 'mm':
            """
            checks['optimizeScene_result'] = optimizeScene_result
            checks['checkName_result'] = checkName_result
            checks['checkMainCamera_result'] = checkMainCamera_result
            #checks['checkCameraBGImg_result'] = checkCameraBGImg_result
            checks['checkLockCamera_result'] = checkLockCamera_result
            checks['checkRenderLayers_result'] = checkRenderLayers_result
            checks['checkLighting_result'] = checkLighting_result
            """
            # optimizeScene_result = checks.get('optimizeScene_result')
            # optimizeSceneDetection = OptimizeSceneDetection(optimizeScene_result,self.btn_style)
            # self.main_layout.addWidget(optimizeSceneDetection)
            #
            # checkName_result = checks.get('checkName_result')
            # nameDetection = NameDetection(checkName_result,self.btn_style)
            # self.main_layout.addWidget(nameDetection)

            checkMainCamera_result = checks.get('checkMainCamera_result')
            mainCameraDetection = MainCameraDetection(checkMainCamera_result,self.big_font,self.btn_style)
            self.main_layout.addWidget(mainCameraDetection)

            # checkCameraBGImg_result = checks.get('checkCameraBGImg_result')
            # cameraBGImgDetection = CameraBGImgDetection(checkCameraBGImg_result,self.btn_style)
            # self.main_layout.addWidget(cameraBGImgDetection)


            checkLockCamera_result = checks.get('checkLockCamera_result')
            lockCameraDetection = LockCameraDetection(checkLockCamera_result,self.big_font,self.btn_style)
            self.main_layout.addWidget(lockCameraDetection)


            checkRenderLayers_result = checks.get('checkRenderLayers_result')
            renderLayoutDetection = RenderLayoutDetection(checkRenderLayers_result,self.big_font,self.btn_style)
            self.main_layout.addWidget(renderLayoutDetection)

            # primMaterial_result_info = {'result': 'OK', 'info': []}
            # primMaterialDetetion =PrimMaterialDetetion(primMaterial_result_info,self.btn_style)
            # self.main_layout.addWidget(primMaterialDetetion)

        elif pipeline == 'mod':
            """
            checks['optimizeScene_result'] = optimizeScene_result
            checks['checkName_result'] = checkName_result
            checks['checkDisplayLayers_result'] = checkDisplayLayers_result
            checks['checkRenderLayers_result'] = checkRenderLayers_result
            checks['checkPrimMaterial_result'] = checkPrimMaterial_result
            checks['checkTex_result'] = checkTex_result
            checks['checkUV_result'] = checkUV_result
            # checks['checkColorSpace_result'] = checkColorSpace_result
            checks['checkOverFourFace_result'] = checkOverFourFace_result
            checks['checkCamera_result'] = checkCamera_result
            checks['checkLighting_result'] = checkLighting_result
            checks['checkYPos_result'] = checkYPos_result
            """

            # if eps != 'Asset':
            #     checkMainCamera_result = checks.get('checkMainCamera_result')
            #     mainCameraDetection = MainCameraDetection(checkMainCamera_result,self.btn_style)
            #     self.main_layout.addWidget(mainCameraDetection)
            checkCamera_result = checks.get('checkCamera_result')
            cameraDetection = CameraDetection(checkCamera_result,self.big_font,self.btn_style)
            self.main_layout.addWidget(cameraDetection)

            checkDisplayLayers_result = checks.get('checkDisplayLayers_result')
            displayLayoutDetection = DisplayLayoutDetection(checkDisplayLayers_result,self.big_font,self.btn_style)
            self.main_layout.addWidget(displayLayoutDetection)

            checkRenderLayers_result = checks.get('checkRenderLayers_result')
            renderLayoutDetection = RenderLayoutDetection(checkRenderLayers_result,self.big_font,self.btn_style)
            self.main_layout.addWidget(renderLayoutDetection)

            checkPrimMaterial_result = checks.get('checkPrimMaterial_result')
            primMaterialDetetion = PrimMaterialDetetion(checkPrimMaterial_result,self.big_font,self.btn_style)
            self.main_layout.addWidget(primMaterialDetetion)

            # checkTex_result = checks.get('checkTex_result')  # 模型不需要检测贴图是否在本地
            # texDetetion = FileMaterialDetetion(checkTex_result, self.btn_style)
            # self.main_layout.addWidget(texDetetion)

            checkUV_result = checks.get('checkUV_result')
            uvDetetion = UVDetetion(checkUV_result,self.big_font, self.btn_style)
            self.main_layout.addWidget(uvDetetion)

            # checkColorSpace_result = checks.get('checkColorSpace_result')
            # colorSpaceDetetion = ColorSpaceDetetion(checkColorSpace_result,self.big_font, self.btn_style)
            # self.main_layout.addWidget(colorSpaceDetetion)

            checkOverFourFace_result = checks.get('checkOverFourFace_result')
            overFourFaceDetetion = OverFourFaceDetetion(checkOverFourFace_result,self.big_font, self.btn_style)
            self.main_layout.addWidget(overFourFaceDetetion)

            checkYPos_result = checks.get('checkYPos_result')
            yPosDetetion = YPosDetetion(checkYPos_result,self.big_font, self.btn_style)
            self.main_layout.addWidget(yPosDetetion)

        elif pipeline == 'cfx':
            """
            checks['optimizeScene_result'] = optimizeScene_result
            //checks['checkName_result'] = checkName_result
            checks['checkDisplayLayers_result'] = checkDisplayLayers_result
            checks['checkRenderLayers_result'] = checkRenderLayers_result
            //checks['checkPrimMaterial_result'] = checkPrimMaterial_result

            checks['checkUV_result'] = checkUV_result
            checks['checkColorSpace_result'] = checkColorSpace_result
            checks['checkOverFourFace_result'] = checkOverFourFace_result
            checks['checkCamera_result'] = checkCamera_result
            checks['checkLighting_result'] = checkLighting_result

            """

            checkCamera_result = checks.get('checkCamera_result')
            cameraDetection = CameraDetection(checkCamera_result,self.big_font,self.btn_style)
            self.main_layout.addWidget(cameraDetection)

            checkDisplayLayers_result = checks.get('checkDisplayLayers_result')
            displayLayoutDetection = DisplayLayoutDetection(checkDisplayLayers_result,self.big_font,self.btn_style)
            self.main_layout.addWidget(displayLayoutDetection)

            checkRenderLayers_result = checks.get('checkRenderLayers_result')
            renderLayoutDetection = RenderLayoutDetection(checkRenderLayers_result,self.big_font,self.btn_style)
            self.main_layout.addWidget(renderLayoutDetection)

            # checkPrimMaterial_result = checks.get('checkPrimMaterial_result')
            # primMaterialDetetion = PrimMaterialDetetion(checkPrimMaterial_result,self.big_font,self.btn_style)
            # self.main_layout.addWidget(primMaterialDetetion)

            checkUV_result = checks.get('checkUV_result')
            uvDetetion = UVDetetion(checkUV_result,self.big_font, self.btn_style)
            self.main_layout.addWidget(uvDetetion)

            checkColorSpace_result = checks.get('checkColorSpace_result')
            colorSpaceDetetion = ColorSpaceDetetion(checkColorSpace_result,self.big_font, self.btn_style)
            self.main_layout.addWidget(colorSpaceDetetion)

            checkOverFourFace_result = checks.get('checkOverFourFace_result')
            overFourFaceDetetion = OverFourFaceDetetion(checkOverFourFace_result,self.big_font, self.btn_style)
            self.main_layout.addWidget(overFourFaceDetetion)

            # checkYPos_result = checks.get('checkYPos_result')
            # yPosDetetion = YPosDetetion(checkYPos_result,self.big_font, self.btn_style)
            # self.main_layout.addWidget(yPosDetetion)

        elif pipeline == 'ani':
            """
            checks['optimizeScene_result'] = optimizeScene_result
            checks['checkName_result'] = checkName_result
            checks['checkMainCamera_result'] = checkMainCamera_result
            checks['checkDisplayLayers_result'] = checkDisplayLayers_result
            checks['checkRenderLayers_result'] = checkRenderLayers_result
            checks['checkPrimMaterial_result'] = checkPrimMaterial_result
            checks['checkLighting_result'] = checkLighting_result
            """

            if eps != 'Asset':
                checkMainCamera_result = checks.get('checkMainCamera_result')
                mainCameraDetection = MainCameraDetection(checkMainCamera_result,self.big_font,self.btn_style)
                self.main_layout.addWidget(mainCameraDetection)

            checkDisplayLayers_result = checks.get('checkDisplayLayers_result')
            displayLayoutDetection = DisplayLayoutDetection(checkDisplayLayers_result,self.big_font,self.btn_style)
            self.main_layout.addWidget(displayLayoutDetection)

            checkRenderLayers_result = checks.get('checkRenderLayers_result')
            renderLayoutDetection = RenderLayoutDetection(checkRenderLayers_result,self.big_font,self.btn_style)
            self.main_layout.addWidget(renderLayoutDetection)

            checkPrimMaterial_result = checks.get('checkPrimMaterial_result')
            primMaterialDetetion = PrimMaterialDetetion(checkPrimMaterial_result,self.big_font,self.btn_style)

            self.main_layout.addWidget(primMaterialDetetion)
            # print('1111111111')

        elif pipeline == 'rig':
            """
            checks['optimizeScene_result'] = optimizeScene_result
            checks['checkName_result'] = checkName_result
            checks['checkDisplayLayers_result'] = checkDisplayLayers_result
            checks['checkRenderLayers_result'] = checkRenderLayers_result
            checks['checkRigGrp_result'] = checkRigGrp_result
            ? checks['checkHumanRig_result'] = checkHumanRig_result 
            checks['checkLighting_result'] = checkLighting_result
            """
            checkRigGrp_result = checks.get('checkRigGrp_result')
            rigGrpDetetion = RigGrpDetetion(checkRigGrp_result,self.big_font,self.btn_style)
            self.main_layout.addWidget(rigGrpDetetion)

            checkDisplayLayers_result = checks.get('checkDisplayLayers_result')
            displayLayoutDetection = DisplayLayoutDetection(checkDisplayLayers_result,self.big_font,self.btn_style)
            self.main_layout.addWidget(displayLayoutDetection)

            checkRenderLayers_result = checks.get('checkRenderLayers_result')
            renderLayoutDetection = RenderLayoutDetection(checkRenderLayers_result,self.big_font,self.btn_style)
            self.main_layout.addWidget(renderLayoutDetection)

            if task_name.endswith('human'):
                checkHumanRig_result = checks.get('checkHumanRig_result')
                rigHumanDetetion = RigHumanDetetion(checkHumanRig_result,self.big_font,self.btn_style)
                self.main_layout.addWidget(rigHumanDetetion)


        elif pipeline == 'env':
            """
            checks['optimizeScene_result'] = optimizeScene_result
            checks['checkName_result'] = checkName_result
            checks['checkMainCamera_result'] = checkMainCamera_result
            #checks['checkCameraBGImg_result'] = checkCameraBGImg_result
            checks['checkLockCamera_result'] = checkLockCamera_result
            checks['checkRenderLayers_result'] = checkRenderLayers_result
            checks['checDSO_result'] = checDSO_result
            checks['checkLighting_result'] = checkLighting_result
            """


            checkMainCamera_result = checks.get('checkMainCamera_result')
            mainCameraDetection = MainCameraDetection(checkMainCamera_result,self.big_font,self.btn_style)
            self.main_layout.addWidget(mainCameraDetection)

            checkCameraBGImg_result = checks.get('checkCameraBGImg_result')
            cameraBGImgDetection = CameraBGImgDetection(checkCameraBGImg_result,self.big_font,self.btn_style)
            self.main_layout.addWidget(cameraBGImgDetection)

            checkLockCamera_result = checks.get('checkLockCamera_result')
            lockCameraDetection = LockCameraDetection(checkLockCamera_result,self.big_font,self.btn_style)
            self.main_layout.addWidget(lockCameraDetection)

            checkDisplayLayers_result = checks.get('checkDisplayLayers_result')
            displayLayoutDetection = DisplayLayoutDetection(checkDisplayLayers_result,self.big_font,self.btn_style)
            self.main_layout.addWidget(displayLayoutDetection)

            checkRenderLayers_result = checks.get('checkRenderLayers_result')
            renderLayoutDetection = RenderLayoutDetection(checkRenderLayers_result,self.big_font,self.btn_style)
            self.main_layout.addWidget(renderLayoutDetection)

            checDSO_result = checks.get('checDSO_result')
            dsoDetection = DSODetetion(checDSO_result,self.big_font,self.btn_style)
            self.main_layout.addWidget(dsoDetection)



    def _close(self):
        self.close()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    mm_checks = {'optimizeScene_result':{'result':'OK','info':''},
                 'checkName_result':{'result':'OK','info':[]},
              'checkMainCamera_result':{'result':'OK','info':''},
              'checkCameraBGImg_result':{'result':'OK','info':''},
              'checkLockCamera_result':{'result':'ERROR','info':['tx','ty']},
              'checkRenderLayers_result':{'result':'OK','info':[]}}

    ani_checks = {'optimizeScene_result':{'result':'OK','info':''},
                  'checkName_result': {'result': 'ERROR', 'info': ['group1|cube1']},
              'checkMainCamera_result':{'result':'OK','info':''},
              'checkDisplayLayers_result':{'result':'ERROR','info':['disp','cip']},
              'checkPrimMaterial_result':{'result':'ERROR','info':['che|mesh1','deng|mesh2']},
              'checkRenderLayers_result':{'result':'OK','info':[]}}

    # d = DetetionWindow('mm','eps01','mm',mm_checks)
    d = DetetionWindow('ani','eps01','ani',ani_checks)
    d.show()
    sys.exit(app.exec_())
















